<nav class="navbar navbar-expand-lg bg-body-tertiary">
    <div class="container-fluid">
        <a class="navbar-brand" href="/">Redis实验</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link active" href="/index2/">实验一</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/chat/">实验二</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/admin/auth/user/?_facets=True">实验三</a>
                </li>
            </ul>

            {% if user.is_authenticated %}
                <li class="nav-item dropdown d-flex m-2">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
                       aria-expanded="false">
                        当前登录用户：{{ user.username }}
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="#">个人主页</a></li>
                        {% if user.is_staff %}
                            <li><a class="dropdown-item" href="/admin">管理员端</a></li>
                        {% endif %}
                        <li>
                            <hr class="dropdown-divider">
                        </li>
                        <li>
                            <form id="logout-form" action="{% url 'logout' %}" method="post" style="display: none;">
                                {% csrf_token %}
                            </form>
                            <a class="dropdown-item" href="#" onclick="logout(); return false;">退出登录</a>
                        </li>
                    </ul>
                </li>
            {% else %}
                <nav class="nav-item bg-body-tertiary">
                    <form class="container-fluid justify-content-start">
                        <button class="btn btn-sm btn-outline-success me-2" type="button"
                                onclick="location.href='/login/'">登录
                        </button>
                        <button class="btn btn-sm btn-outline-secondary" type="button"
                                onclick="location.href='/register/'">注册
                        </button>
                    </form>
                </nav>
            {% endif %}

        </div>
    </div>
</nav>